/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.Button
 *  javafx.scene.control.ChoiceBox
 *  javafx.scene.control.TextField
 *  javafx.scene.layout.Pane
 *  javafx.util.StringConverter
 *  org.springframework.beans.BeanUtils
 *  org.springframework.beans.factory.annotation.Autowired
 *  org.springframework.util.CollectionUtils
 */
package com.gys.controller.payingBank;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.BankInfoUtil;
import com.gys.common.business.ShopSortSettingUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.CacheUtil;
import com.gys.common.util.CommonUtil;
import com.gys.controller.BaseController;
import com.gys.controller.payingBank.PayingBankController;
import com.gys.data.example.GetLoginStoreOutData;
import com.gys.data.example.GetStoreSortData;
import com.gys.data.example.GetUserOutData;
import com.gys.data.payingBank.BankInfoInData;
import com.gys.data.payingBank.BankInfoOutData;
import com.gys.data.payingBank.StoreSort;
import com.gys.data.shopSortSetting.GetShopInData;
import com.gys.data.shopSortSetting.importShopExcelInData;
import de.felixroske.jfxsupport.FXMLController;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.util.StringConverter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

@FXMLController
public class AvailableStoreController
extends BaseController
implements Initializable {
    @FXML
    private Button importFileBtn;
    @FXML
    private Button cancelBtn;
    @FXML
    private ChoiceBox<StoreSort> storeSort;
    @FXML
    private Pane modelPane;
    @FXML
    private TextField endStoreNum;
    @FXML
    private TextField startStoreNum;
    @FXML
    private Button exportFileBtn;
    @FXML
    private Button sureBtn;
    List<GetStoreSortData> storeSortData = new ArrayList<GetStoreSortData>();
    List<GetLoginStoreOutData> storeData = new ArrayList<GetLoginStoreOutData>();
    @Autowired
    private PayingBankController payingBankController;

    public void initialize(URL location, ResourceBundle resources) {
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.modelPane)) {
            return;
        }
        this.initPane();
    }

    private void initPane() {
        if (ObjectUtil.isNotEmpty(this.sureBtn)) {
            this.startStoreNum.clear();
            this.endStoreNum.clear();
            this.storeSort.getItems().clear();
        }
        this.storeSort.getItems().addAll(this.getAllStoreSort());
        this.storeSort.converterProperty().set(new StringConverter<StoreSort>(){

            public String toString(StoreSort object) {
                return object.getName();
            }

            public StoreSort fromString(String string) {
                return null;
            }
        });
    }

    private List<StoreSort> getAllStoreSort() {
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("clientId", ((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        HttpJson httpJson = ShopSortSettingUtil.querySort(param);
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return null;
        }
        this.storeSortData = JSON.parseArray((String)httpJson.getMsg(), GetStoreSortData.class);
        ArrayList<StoreSort> list = new ArrayList<StoreSort>();
        this.storeSortData.forEach(item -> list.add(new StoreSort(item.getGssgIdSort(), item.getGssgNameSort())));
        return list;
    }

    @FXML
    void updateBankInfo() {
        BankInfoOutData outData = new BankInfoOutData();
        if (!CollectionUtils.isEmpty(this.payingBankController.getObservableTableList())) {
            for (BankInfoOutData i : this.payingBankController.getObservableTableList()) {
                if (!i.getCheckBox().isSelected().booleanValue()) continue;
                outData = i;
            }
        }
        String minStoreNum = this.startStoreNum.getText().trim();
        String maxStoreNum = this.endStoreNum.getText().trim();
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("clientId", ((GetUserOutData)CacheUtil.get("logInUser")).getClient());
        HttpJson httpJson = ShopSortSettingUtil.queryStore(param);
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        this.storeData = JSON.parseArray((String)httpJson.getMsg(), GetLoginStoreOutData.class);
        ArrayList<String> list = new ArrayList();
        this.storeData.forEach(item -> list.add(item.getStoCode()));
        StringBuffer sb = new StringBuffer();
        if (list.size() > 0) {
            for (String s : list) {
                if (Long.parseLong(s) < Long.parseLong(minStoreNum) && Long.parseLong(s) > Long.parseLong(maxStoreNum)) continue;
                sb.append(s).append(",");
            }
        }
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        BankInfoInData inData = new BankInfoInData();
        inData.setGsbsBrId(sb.toString().substring(0, sb.toString().length() - 1));
        inData.setClientId(outData.getClientId());
        inData.setGsbsBankId(outData.getGsbsBankId());
        inData.setGsbsBankName(outData.getGsbsBankName());
        inData.setGsbsBankAccount(outData.getGsbsBankAccount());
        HttpJson rsp = BankInfoUtil.editBankInfo(inData);
        if (rsp.isSuccess()) {
            alert.setContentText("\u66f4\u65b0\u6210\u529f");
            alert.showAndWait();
            this.closeWindow();
            this.payingBankController.initTable();
        } else {
            alert.setContentText("\u8bf7\u4fee\u6539");
            alert.showAndWait();
        }
    }

    @FXML
    void exportFileAction() {
        CommonUtil.exportModelFile("\u95e8\u5e97\u5206\u7c7b\u5bfc\u5165\u6a21\u677f", "/modelFile/shopSortModelFile.xls");
    }

    @FXML
    void importFileAction() throws Exception {
        File file = CommonUtil.fileChooser();
        if (ObjectUtil.isEmpty(file)) {
            return;
        }
        List<importShopExcelInData> importExcelInData = CommonUtil.importExcel(file, 0, importShopExcelInData.class);
        if (ObjectUtil.isEmpty(importExcelInData)) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u6ca1\u6709\u6709\u6548\u6570\u636e");
            alert.showAndWait();
            return;
        }
        ArrayList inDataList = new ArrayList();
        GetUserOutData user = this.getLoginUser();
        String account = user.getAccount();
        importExcelInData.forEach(item -> {
            GetShopInData inData = new GetShopInData();
            BeanUtils.copyProperties(item, inData);
            inData.setGssgUpdateEmp(account);
            inData.setClientId(((GetUserOutData)CacheUtil.get("logInUser")).getClient());
            inDataList.add(inData);
        });
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("shopInData", inDataList);
        HttpJson httpJson = ShopSortSettingUtil.addAll(param);
        CommonUtil.handleHttpResOnlyAlert(httpJson, "\u4fdd\u5b58\u6210\u529f");
        this.initPane();
    }

    @FXML
    private void closeWindow() {
        this.modelPane.getScene().getWindow().hide();
    }

    public Button getImportFileBtn() {
        return this.importFileBtn;
    }

    public Button getCancelBtn() {
        return this.cancelBtn;
    }

    public ChoiceBox<StoreSort> getStoreSort() {
        return this.storeSort;
    }

    public Pane getModelPane() {
        return this.modelPane;
    }

    public TextField getEndStoreNum() {
        return this.endStoreNum;
    }

    public TextField getStartStoreNum() {
        return this.startStoreNum;
    }

    public Button getExportFileBtn() {
        return this.exportFileBtn;
    }

    public Button getSureBtn() {
        return this.sureBtn;
    }

    public List<GetStoreSortData> getStoreSortData() {
        return this.storeSortData;
    }

    public List<GetLoginStoreOutData> getStoreData() {
        return this.storeData;
    }

    public PayingBankController getPayingBankController() {
        return this.payingBankController;
    }

    public void setImportFileBtn(Button importFileBtn) {
        this.importFileBtn = importFileBtn;
    }

    public void setCancelBtn(Button cancelBtn) {
        this.cancelBtn = cancelBtn;
    }

    public void setStoreSort(ChoiceBox<StoreSort> storeSort) {
        this.storeSort = storeSort;
    }

    public void setModelPane(Pane modelPane) {
        this.modelPane = modelPane;
    }

    public void setEndStoreNum(TextField endStoreNum) {
        this.endStoreNum = endStoreNum;
    }

    public void setStartStoreNum(TextField startStoreNum) {
        this.startStoreNum = startStoreNum;
    }

    public void setExportFileBtn(Button exportFileBtn) {
        this.exportFileBtn = exportFileBtn;
    }

    public void setSureBtn(Button sureBtn) {
        this.sureBtn = sureBtn;
    }

    public void setStoreSortData(List<GetStoreSortData> storeSortData) {
        this.storeSortData = storeSortData;
    }

    public void setStoreData(List<GetLoginStoreOutData> storeData) {
        this.storeData = storeData;
    }

    public void setPayingBankController(PayingBankController payingBankController) {
        this.payingBankController = payingBankController;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AvailableStoreController)) {
            return false;
        }
        AvailableStoreController other = (AvailableStoreController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        Button this$importFileBtn = this.getImportFileBtn();
        Button other$importFileBtn = other.getImportFileBtn();
        if (this$importFileBtn == null ? other$importFileBtn != null : !this$importFileBtn.equals(other$importFileBtn)) {
            return false;
        }
        Button this$cancelBtn = this.getCancelBtn();
        Button other$cancelBtn = other.getCancelBtn();
        if (this$cancelBtn == null ? other$cancelBtn != null : !this$cancelBtn.equals(other$cancelBtn)) {
            return false;
        }
        ChoiceBox<StoreSort> this$storeSort = this.getStoreSort();
        ChoiceBox<StoreSort> other$storeSort = other.getStoreSort();
        if (this$storeSort == null ? other$storeSort != null : !this$storeSort.equals(other$storeSort)) {
            return false;
        }
        Pane this$modelPane = this.getModelPane();
        Pane other$modelPane = other.getModelPane();
        if (this$modelPane == null ? other$modelPane != null : !this$modelPane.equals(other$modelPane)) {
            return false;
        }
        TextField this$endStoreNum = this.getEndStoreNum();
        TextField other$endStoreNum = other.getEndStoreNum();
        if (this$endStoreNum == null ? other$endStoreNum != null : !this$endStoreNum.equals(other$endStoreNum)) {
            return false;
        }
        TextField this$startStoreNum = this.getStartStoreNum();
        TextField other$startStoreNum = other.getStartStoreNum();
        if (this$startStoreNum == null ? other$startStoreNum != null : !this$startStoreNum.equals(other$startStoreNum)) {
            return false;
        }
        Button this$exportFileBtn = this.getExportFileBtn();
        Button other$exportFileBtn = other.getExportFileBtn();
        if (this$exportFileBtn == null ? other$exportFileBtn != null : !this$exportFileBtn.equals(other$exportFileBtn)) {
            return false;
        }
        Button this$sureBtn = this.getSureBtn();
        Button other$sureBtn = other.getSureBtn();
        if (this$sureBtn == null ? other$sureBtn != null : !this$sureBtn.equals(other$sureBtn)) {
            return false;
        }
        List<GetStoreSortData> this$storeSortData = this.getStoreSortData();
        List<GetStoreSortData> other$storeSortData = other.getStoreSortData();
        if (this$storeSortData == null ? other$storeSortData != null : !(this$storeSortData).equals(other$storeSortData)) {
            return false;
        }
        List<GetLoginStoreOutData> this$storeData = this.getStoreData();
        List<GetLoginStoreOutData> other$storeData = other.getStoreData();
        if (this$storeData == null ? other$storeData != null : !(this$storeData).equals(other$storeData)) {
            return false;
        }
        PayingBankController this$payingBankController = this.getPayingBankController();
        PayingBankController other$payingBankController = other.getPayingBankController();
        return !(this$payingBankController == null ? other$payingBankController != null : !(this$payingBankController).equals(other$payingBankController));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AvailableStoreController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        Button $importFileBtn = this.getImportFileBtn();
        result = result * 59 + ($importFileBtn == null ? 43 : $importFileBtn.hashCode());
        Button $cancelBtn = this.getCancelBtn();
        result = result * 59 + ($cancelBtn == null ? 43 : $cancelBtn.hashCode());
        ChoiceBox<StoreSort> $storeSort = this.getStoreSort();
        result = result * 59 + ($storeSort == null ? 43 : $storeSort.hashCode());
        Pane $modelPane = this.getModelPane();
        result = result * 59 + ($modelPane == null ? 43 : $modelPane.hashCode());
        TextField $endStoreNum = this.getEndStoreNum();
        result = result * 59 + ($endStoreNum == null ? 43 : $endStoreNum.hashCode());
        TextField $startStoreNum = this.getStartStoreNum();
        result = result * 59 + ($startStoreNum == null ? 43 : $startStoreNum.hashCode());
        Button $exportFileBtn = this.getExportFileBtn();
        result = result * 59 + ($exportFileBtn == null ? 43 : $exportFileBtn.hashCode());
        Button $sureBtn = this.getSureBtn();
        result = result * 59 + ($sureBtn == null ? 43 : $sureBtn.hashCode());
        List<GetStoreSortData> $storeSortData = this.getStoreSortData();
        result = result * 59 + ($storeSortData == null ? 43 : ($storeSortData).hashCode());
        List<GetLoginStoreOutData> $storeData = this.getStoreData();
        result = result * 59 + ($storeData == null ? 43 : ($storeData).hashCode());
        PayingBankController $payingBankController = this.getPayingBankController();
        result = result * 59 + ($payingBankController == null ? 43 : ($payingBankController).hashCode());
        return result;
    }

    public String toString() {
        return "AvailableStoreController(importFileBtn=" + this.getImportFileBtn() + ", cancelBtn=" + this.getCancelBtn() + ", storeSort=" + this.getStoreSort() + ", modelPane=" + this.getModelPane() + ", endStoreNum=" + this.getEndStoreNum() + ", startStoreNum=" + this.getStartStoreNum() + ", exportFileBtn=" + this.getExportFileBtn() + ", sureBtn=" + this.getSureBtn() + ", storeSortData=" + this.getStoreSortData() + ", storeData=" + this.getStoreData() + ", payingBankController=" + this.getPayingBankController() + ")";
    }
}

